package com.xxl.job.admin.core.conf;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * description:
 * <p>
 * Date: 2018/12/25
 * <p>
 * Time: 20:19
 *
 * @author zhangxin
 */
@Component
public class JobInfoBatchAddStartExecutor {

    @Value("${thread_pool_config.jobinfo_batch_add_start.core_pool_size:10}")
    private Integer corePoolSize;
    @Value("${thread_pool_config.jobinfo_batch_add_start.max_pool_size:50}")
    private Integer maxPoolSize;
    @Value("${thread_pool_config.jobinfo_batch_add_start.keep_alive_seconds:5}")
    private Integer keepAliveSeconds;

    private ExecutorService executor;

    @PostConstruct
    public void dbExecutorFactory(){
        executor = new ThreadPoolExecutor(corePoolSize, maxPoolSize,
            Long.valueOf(keepAliveSeconds).longValue(), TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(), new BasicThreadFactory("Retry"));
    }

    public Executor getExecutor() {
        return executor;
    }

}
